<template>
  <div class="index">
    <button @click="testAxios">测试接口</button>
  </div>
</template>

<script setup>
import { register } from "~/api/login/index";
// 
const eventSource = new EventSource(import.meta.env.VITE_APP_BASE_API + "/device/sse?params=1");
eventSource.onmessage = ({ data }) => {
  console.log("New message", JSON.parse(data));
};
eventSource.onerror = error => {
  console.log("🚀 ~ error:", error);
};

setTimeout(() => {
  eventSource.close();
}, 5000);

const testAxios = async () => {
  const params = {
    username: "daxiong",
    password: "0JDT001AR",
  };
  try {
    const result = await register(params);
    console.log("🚀 ~ testAxios ~ result:", result);
  } catch (error) {
    console.log("🚀 ~ testAxios ~ error:", error);
  }
};
</script>

<style lang="scss" scoped></style>
